import cv2
import os


def video_cut_jump(video_path):
    file_path, file_name = os.path.split(video_path)
    print(file_path)
    print(file_name)
    save_video_path = os.path.join(file_path, 'demo_' + file_name)
    print(save_video_path)
    video_file = cv2.VideoCapture(video_path)
    resize_h = video_file.get(cv2.CAP_PROP_FRAME_HEIGHT)
    resize_w = video_file.get(cv2.CAP_PROP_FRAME_WIDTH)
    # Set video attribute
    save_fourcc_format = 'mp4v'
    fourcc = cv2.VideoWriter_fourcc(*save_fourcc_format)
    cap_fps = 10
    # fourcc = cv2.VideoWriter_fourcc(*save_fourcc_format)
    cap_size = (int(resize_w), int(resize_h))
    output_save = cv2.VideoWriter(save_video_path, fourcc, cap_fps, cap_size)
    jump_fps = 12
    count = 1
    while True:
        ret, frame = video_file.read()
        if frame is None:
            break
        if count % jump_fps == 0:
            output_save.write(frame)
        count += 1
        # print('current frame:', count)
    video_file.release()
    output_save.release()


if __name__ == "__main__":
    root_path = r'/home/kaijia/algo-env/Utils/sample/aeroplane_location.mp4'
    video_cut_jump(root_path)
